package com.proyecto.core.vista.echo.base;

import java.util.ResourceBundle;

import nextapp.echo2.app.Alignment;
import nextapp.echo2.app.Column;
import nextapp.echo2.app.Extent;
import nextapp.echo2.app.Font;
import nextapp.echo2.app.Insets;
import nextapp.echo2.app.RadioButton;
import nextapp.echo2.app.Row;
import nextapp.echo2.app.button.ButtonGroup;
import nextapp.echo2.app.event.ActionEvent;
import nextapp.echo2.app.event.ActionListener;
import nextapp.echo2.app.layout.RowLayoutData;

import com.proyecto.core.vista.echo.constantes.MensajeTipo;

@SuppressWarnings("serial")
public class RwOptionReporteador extends Row {

	private ResourceBundle resourceBundle;
	public boolean rptPdfPorDefecto = true;
	public String tipoRPT = null;
	
	private ButtonGroup criterio = new ButtonGroup();
	private RadioButton rdoBtnPdf;
	private RadioButton rdoBtnWord;
	private RadioButton rdoBtnExcel;

	/**
	 * Creates a new <code>RwOptionReporteador</code>.
	 */
	public RwOptionReporteador() {
		super();

		// Add design-time configured components.
		initComponents();
		rdoBtnPdf.setActionCommand(MensajeTipo.COMANDO_PDF);
		rdoBtnWord.setActionCommand(MensajeTipo.COMANDO_WORD);
		rdoBtnExcel.setActionCommand(MensajeTipo.COMANDO_EXCEL);
		
		this.setTipoRPT(MensajeTipo.COMANDO_PDF);
	}

	public void porDefecto(boolean rptPdfPorDefecto){
		if(rptPdfPorDefecto){
			rdoBtnPdf.setVisible(true);
			rdoBtnWord.setVisible(false);
			rdoBtnExcel.setVisible(false);
		}else{
			rdoBtnPdf.setVisible(true);
			rdoBtnWord.setVisible(true);
			rdoBtnExcel.setVisible(true);	
		}
	}

	public ButtonGroup getCriterio() {
		return criterio;
	}

	public void setCriterio(ButtonGroup criterio) {
		this.criterio = criterio;
	}

	public RadioButton getRdoBtnExcel() {
		return rdoBtnExcel;
	}

	public void setRdoBtnExcel(RadioButton rdoBtnExcel) {
		this.rdoBtnExcel = rdoBtnExcel;
	}

	public RadioButton getRdoBtnPdf() {
		return rdoBtnPdf;
	}

	public void setRdoBtnPdf(RadioButton rdoBtnPdf) {
		this.rdoBtnPdf = rdoBtnPdf;
	}

	public RadioButton getRdoBtnWord() {
		return rdoBtnWord;
	}

	public void setRdoBtnWord(RadioButton rdoBtnWord) {
		this.rdoBtnWord = rdoBtnWord;
	}

	public boolean isRptPdfPorDefecto() {
		return rptPdfPorDefecto;
	}

	public void setRptPdfPorDefecto(boolean rptPdfPorDefecto) {
		this.rptPdfPorDefecto = rptPdfPorDefecto;
	}

	private void seleccionTipoRptAction(ActionEvent e) {
		//TODO Implement.
		RadioButton rdoBtnTipoRpt = (RadioButton)e.getSource();
		
		if(rdoBtnTipoRpt.getText().equals("Pdf") ){
			this.setTipoRPT(MensajeTipo.COMANDO_PDF);
		}
		if(rdoBtnTipoRpt.getText().equals("Procesador Texto") ){
			this.setTipoRPT(MensajeTipo.COMANDO_WORD);
		}
		if(rdoBtnTipoRpt.getText().equals("Hoja Calculo") ){
			this.setTipoRPT(MensajeTipo.COMANDO_EXCEL);
		}
	}

	public String getTipoRPT() {
		return tipoRPT;
	}

	public void setTipoRPT(String tipoRPT) {
		this.tipoRPT = tipoRPT;
	}

	public void setVisibleRdoBtnTipoPdf(boolean visible){
		rdoBtnPdf.setVisible(visible);
	}

	public void setVisibleRdoBtnTipoWord(boolean visible){
		rdoBtnWord.setVisible(visible);
	}

	public void setVisibleRdoBtnTipoExcel(boolean visible){
		rdoBtnExcel.setVisible(visible);
	}
	/**
	 * Configures initial state of component.
	 * WARNING: AUTO-GENERATED METHOD.
	 * Contents will be overwritten.
	 */
	private void initComponents() {
		this.setStyleName("2OpenLabs.Row.BotoneraInterna");
		rdoBtnPdf = new RadioButton();
		rdoBtnPdf.setSelected(true);
		rdoBtnPdf.setText("Pdf");
		ButtonGroup criterioTipoRpt = new ButtonGroup();
		rdoBtnPdf.setGroup(criterioTipoRpt);
		rdoBtnPdf.setToolTipText("Mostrar Reporte en PDF");
		RowLayoutData rdoBtnPdfLayoutData = new RowLayoutData();
		rdoBtnPdfLayoutData.setInsets(new Insets(new Extent(0, Extent.PX),
				new Extent(0, Extent.PX), new Extent(15, Extent.PX),
				new Extent(0, Extent.PX)));
		rdoBtnPdfLayoutData.setAlignment(new Alignment(Alignment.CENTER,
				Alignment.DEFAULT));
		rdoBtnPdf.setLayoutData(rdoBtnPdfLayoutData);
		rdoBtnPdf.setFont(new Font(new Font.Typeface("serif"), Font.PLAIN,
				new Extent(9, Extent.PT)));
		rdoBtnPdf.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				seleccionTipoRptAction(e);
			}
		});
		add(rdoBtnPdf);
		rdoBtnWord = new RadioButton();
		rdoBtnWord.setText("Procesador Texto");
		rdoBtnWord.setGroup(criterioTipoRpt);
		rdoBtnWord.setToolTipText("Mostrar Reporte en Procesador de Texto");
		RowLayoutData rdoBtnWordLayoutData = new RowLayoutData();
		rdoBtnWordLayoutData.setInsets(new Insets(new Extent(0, Extent.PX),
				new Extent(0, Extent.PX), new Extent(15, Extent.PX),
				new Extent(0, Extent.PX)));
		rdoBtnWordLayoutData.setAlignment(new Alignment(Alignment.CENTER,
				Alignment.DEFAULT));
		rdoBtnWord.setLayoutData(rdoBtnWordLayoutData);
		rdoBtnWord.setFont(new Font(new Font.Typeface("serif"), Font.PLAIN,
				new Extent(9, Extent.PT)));
		rdoBtnWord.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				seleccionTipoRptAction(e);
			}
		});
		add(rdoBtnWord);
		rdoBtnExcel = new RadioButton();
		rdoBtnExcel.setText("Hoja Calculo");
		rdoBtnExcel.setGroup(criterioTipoRpt);
		rdoBtnExcel.setToolTipText("Mostrar Reporte en Hoja de Calculo");
		rdoBtnExcel.setStyleName("OpenLabs.rbtnDefault");
		RowLayoutData rdoBtnExcelLayoutData = new RowLayoutData();
		rdoBtnExcelLayoutData.setInsets(new Insets(new Extent(0, Extent.PX),
				new Extent(0, Extent.PX), new Extent(0, Extent.PX), new Extent(
						0, Extent.PX)));
		rdoBtnExcelLayoutData.setAlignment(new Alignment(Alignment.CENTER,
				Alignment.DEFAULT));
		rdoBtnExcel.setLayoutData(rdoBtnExcelLayoutData);
		rdoBtnExcel.setFont(new Font(new Font.Typeface("serif"), Font.PLAIN,
				new Extent(9, Extent.PT)));
		rdoBtnExcel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				seleccionTipoRptAction(e);
			}
		});
		add(rdoBtnExcel);
	}


}
